package com.sprucetec.live.config;

import lombok.extern.slf4j.Slf4j;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author: Wangshaobo
 * @date: 2018/12/27 17:35
 * @description: beetl 模板加载器
 */
@Slf4j
@Configuration
public class BeetlGroupTemplate {

    @Bean(initMethod = "init", name = "groupTemplate")
    public GroupTemplate getGroupTemplate() {
        ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader("/static/template");
        org.beetl.core.Configuration cfg = null;
        try {
            cfg = org.beetl.core.Configuration.defaultConfiguration();
        } catch (IOException e) {
            log.error("获取GroupTemplate失败",e);
        }

        return new GroupTemplate(resourceLoader, cfg);
    }
}
